package ds.tree;

public class MirrorTrees {

	private static class TreeNode{
		int value;
		TreeNode left = null;
		TreeNode right = null;
		
		TreeNode(int val){
			this.value = val;
		}
		
		public String toString(){
			return String.valueOf(value);
		}
	}
	
	public void inOrderTraversal(TreeNode node){
		if(node == null){
			return;
		}
		inOrderTraversal(node.left);
		System.out.print(node + " ");
		inOrderTraversal(node.right);
	}
	public void mirror(TreeNode node){
		if(node == null){
			return;
		}
		mirror(node.left);
		mirror(node.right);
		
		TreeNode temp = node.left;
		node.left = node.right;
		node.right = temp;
	}
	private static TreeNode tree(){
		TreeNode A = new TreeNode(1);
		TreeNode B = new TreeNode(2);
		TreeNode C = new TreeNode(3);
		TreeNode D = new TreeNode(4);
		TreeNode E = new TreeNode(5);
		TreeNode F = new TreeNode(6);
		
		A.left = C;
		A.right = B;
		B.left = E;
		B.right = D;
		return A;
	}	
	public static void main(String[] args) {
		MirrorTrees mtrees = new MirrorTrees();
		TreeNode node = tree();
		mtrees.inOrderTraversal(node);
		mtrees.mirror(node);
		System.out.println();
		mtrees.inOrderTraversal(node);
		
	}

}
